import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
 roles: ['admin','editor']    control the page roles (you can set multiple roles)
 title: 'title'               the name show in sidebar and breadcrumb (recommend set)
 icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
 breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
 activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
 }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
]

export let myrouter = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/print',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/print/:pid',
        component: () => import('@/views/print/index')
      }
    ]
  },
  {
    path: '/',
    redirect: '/home/homepage',
  },
  {
    path: '/home',
    component: Layout,
    name: '',
    meta: {title: '首页', icon: 'homepage'},
    children: [
      {
        path: 'homepage',
        name: 'homepage',
        component: () => import('@/views/homepage/index'),
        meta: {title: '首页',}
      },
      {
        path: 'beginnerGuide',
        name: 'beginnerGuide',
        component: () => import('@/views/beginner-guide/index'),
        meta: {title: '新手向导',},
        hidden: true
      },
    ]
  },
  {
    path: '/basic_settings',
    component: Layout,
    name: 'basic_settings',
    meta: {title: '资料设置', icon: 'data-nav'},
    children: [
      {
        path: 'product_manager',
        name: 'product_manager',
        component: () => import('@/views/product-manager/index'),
        meta: {title: '商品', icon: 'product-manager-nav'}
      },
      {
        path: 'customer_settings',
        name: 'customer_settings',
        component: () => import('@/views/customer-settings/index'),
        meta: {title: '客户', icon: 'customer-settings-nav'}
      },
      {
        path: 'warehouse_settings',
        name: 'warehouse_settings',
        component: () => import('@/views/warehouse-settings/index'),
        meta: {title: '仓库', icon: 'warehouse-settings-nav'}
      },
      {
        path: 'shop',
        name: 'shop',
        component: () => import('@/views/shop/index'),
        meta: { title: '门店',  icon: 'shop' }
      },
      {
        path: 'supplier_manager',
        name: 'supplier_manager',
        component: () => import('@/views/supplier-manager/index'),
        meta: {title: '供应商', icon: 'supplier-manager-nav'}
      },
      {
        path: 'settlement_account',
        name: 'settlement_account',
        component: () => import('@/views/settlement-account/index'),
        meta: { title: '结算账户',  icon: 'settlement-account-nav' }
      },
      {
        path: 'unit',
        name: 'unit',
        component: () => import('@/views/unit/index'),
        meta: { title: '计量单位',  icon: 'unit' }
      },
      //   path: 'account_set_management',
      //   name: 'account_set_management',
      //   component: () => import('@/views/account-set-management/index'),
      //   meta: { title: '账套管理',  }
      // },
      // {
      //   path: 'operator_settings',
      //   name: 'operator_settings',
      //   component: () => import('@/views/operator-settings/index'),
      //   meta: { title: '操作员设置',  }
      // },
      // {
      //   path: 'role_management',
      //   name: 'role_management',
      //   component: () => import('@/views/role-management/index'),
      //   meta: { title: '角色管理',  }
      // },
      // {
      //   path: 'system_settings',
      //   name: 'system_settings',
      //   component: () => import('@/views/system-settings/index'),
      //   meta: { title: '系统设置',  }
      // },
      // {
      //   path: 'department_management',
      //   name: 'department_management',
      //   component: () => import('@/views/department-management/index'),
      //   meta: { title: '部门管理',  }
      // },
      // {
      // {
      //   path: 'data_backup',
      //   name: 'data_backup',
      //   component: () => import('@/views/data-backup/index'),
      //   meta: { title: '数据备份',  }
      // },
      // {
      //   path: 'system_upkeep',
      //   name: 'system_upkeep',
      //   component: () => import('@/views/system-upkeep/index'),
      //   meta: { title: '系统维护',  }
      // },
    ]
  },
  {
    path: '/stock_manager',
    component: Layout,
    name: 'stock_manager',
    meta: {title: '进货管理', icon: 'stock-in'},
    children: [
      {
        path: 'purchase_incoming',
        name: 'purchase_incoming',
        report: 'purchase_incoming_report',
        component: () => import('@/views/purchase-incoming/index'),
        meta: {title: '进货单', icon: 'purchase_incoming_nav'},
      },
      {
        name: 'purchase_incoming_report',
        path: 'purchase_incoming_report',
        meta: {
          title: '进货报表',
          activeMenu: '/stock_manager/purchase_incoming'
        },
        component: () => import('@/views/purchase-incoming/list'),
        hidden: true,
      },
      {
        path: 'purchase_incoming_detail/:_pid',
        name: 'purchase_incoming_detail',
        component: () => import('@/views/purchase-incoming/index'),
        meta: {
          title: '进货单详情', icon: 'purchase_incoming_nav',
        },
        hidden: true,
      },
      {
        path: 'purchase_return',
        name: 'purchase_return',
        report: 'purchase_return_report',
        component: () => import('@/views/purchase-return/index'),
        meta: {title: '进货退货', icon: 'purchase_return_nav'}
      },
      {
        name: 'purchase_return_report',
        path: 'purchase_return_report',
        meta: {
          title: '进货退货报表',
          activeMenu: '/stock_manager/purchase_return'
        },
        component: () => import('@/views/purchase-return/list'),
        hidden: true,
      },
      // {
      //   path: 'inventory_statistics',
      //   name: 'inventory_statistics',
      //   component: () => import('@/views/customer-settings/index'),
      //   meta: {title: '入库统计', icon: 'inventory_statistics_nav'}
      // },
      // {
      //   path: 'production_incoming',
      //   name: 'production_incoming',
      //   component: () => import('@/views/supplier-manager/index'),
      //   meta: {title: '生产入库', icon: 'production_incoming_nav'}
      // },
      // {
      //   path: 'production_return',
      //   name: 'production_return',
      //   component: () => import('@/views/customer-settings/index'),
      //   meta: {title: '生产退回', icon: 'production_return_nav'}
      // },
      // {
      //   path: 'return_statistics',
      //   name: 'return_statistics',
      //   component: () => import('@/views/warehouse-settings/index'),
      //   meta: {title: '退货统计', icon: 'return_statistics_nav'}
      // },
    ]
  },
  {
    path: '/sale_manager',
    component: Layout,
    name: 'sale_manager',
    meta: {title: '销售管理', icon: 'sale-nav'},
    children: [
      {
        path: 'product_sale',
        name: 'product_sale',
        report: 'product_sale_report',
        component: () => import('@/views/product-sale/index'),
        meta: {title: '销售', icon: 'product_sale_nav'}
      },
      {
        path: 'product_sale_detail/:_pid',
        name: 'product_sale_detail',
        component: () => import('@/views/product-sale/index'),
        meta: {
          title: '销售单详情', icon: 'purchase_incoming_nav',
          activeMenu: '/sale_manager/product_sale'
        },
        hidden: true,
      },
      {
        name: 'product_sale_report',
        path: 'product_sale_report',
        meta: {
          title: '销售报表',
          activeMenu: '/sale_manager/product_sale'
        },
        component: () => import('@/views/product-sale/list'),
        hidden: true,
      },
      {
        path: 'sale_return',
        name: 'sale_return',
        report: 'sale_return_report',
        component: () => import('@/views/sale-return/index'),
        meta: {title: '销售退货', icon: 'sale_return_nav'}
      },
      {
        name: 'sale_return_report',
        path: 'sale_return_report',
        meta: {
          title: '销售退货报表',
          activeMenu: '/sale_manager/sale_return'
        },
        component: () => import('@/views/sale-return/list'),
        hidden: true,
      },
      // {
      //   path: 'retail',
      //   name: 'retail',
      //   component: () => import('@/views/retail/index'),
      //   meta: {title: '零售', icon: 'retail_nav'}
      // },
    ]
  },
  {
    path: '/inventory_management',
    component: Layout,
    name: 'inventory_management',
    meta: {title: '库存管理', icon: 'inventory-nav'},
    children: [
      {
        path: 'product_inventory',
        name: 'product_inventory',
        component: () => import('@/views/product-inventory/index'),
        meta: {title: '商品库存', icon: 'product_inventory_nav'}
      },
      {
        path: 'inventory_alert',
        name: 'inventory_alert',
        component: () => import('@/views/inventory-alert/index'),
        meta: {title: '库存报警', icon: 'inventory_alert_nav'}
      },
      {
        path: 'inventory_check',
        name: 'inventory_check',
        report: 'inventory_check_report',
        component: () => import('@/views/inventory-check/index'),
        meta: {title: '库存盘点', icon: 'inventory_check_nav'}
      },
      {
        name: 'inventory_check_report',
        path: 'inventory_check_report',
        meta: {
          title: '库存盘点表',
          activeMenu: '/inventory_management/inventory_check'
        },
        component: () => import('@/views/inventory-check/list'),
        hidden: true,
      },
      {
        path: 'transfer_order',
        name: 'transfer_order',
        report: 'transfer_order_report',
        component: () => import('@/views/transfer-order/index'),
        meta: {title: '调拨单', icon: 'transfer_order_nav'}
      },
      {
        name: 'transfer_order_report',
        path: 'transfer_order_report',
        meta: {
          title: '调拨单报表',
          activeMenu: '/inventory_management/transfer_order'
        },
        component: () => import('@/views/transfer-order/list'),
        hidden: true,
      },
      {
        path: 'other_incoming_goods_order',
        name: 'other_incoming_goods_order',
        report: 'other_incoming_goods_order_report',
        component: () => import('@/views/other-incoming-goods-order/index'),
        meta: {title: '其他入库单', icon: 'other_incoming_goods_order_nav'}
      },
      {
        name: 'other_incoming_goods_order_report',
        path: 'other_incoming_goods_order_report',
        meta: {
          title: '库存盘点表',
          activeMenu: '/inventory_management/other_incoming_goods_order'
        },
        component: () => import('@/views/other-incoming-goods-order/list'),
        hidden: true,
      },
      {
        path: 'other_outgoing_goods_order',
        name: 'other_outgoing_goods_order',
        report: 'other_outgoing_goods_order_report',
        component: () => import('@/views/other-outgoing-goods-order/index'),
        meta: {title: '其它出库单', icon: 'other_outgoing_goods_order_nav'}
      },
      {
        name: 'other_outgoing_goods_order_report',
        path: 'other_outgoing_goods_order_report',
        meta: {
          title: '库存盘点表',
          activeMenu: '/inventory_management/other_outgoing_goods_order'
        },
        component: () => import('@/views/other-outgoing-goods-order/list'),
        hidden: true,
      },
    ]
  },
  {
    path: '/financial_statements',
    component: Layout,
    name: 'financial_statements',
    meta: {title: '财务管理', icon: 'financial_statements'},
    children: [
      {
        path: 'accounts_receivable',
        name: 'accounts_receivable',
        component: () => import('@/views/accounts-receivable/index'),
        meta: {title: '应收欠款', icon: 'accounts-receivable-nav'}
      },
      {
        path: 'add_accounts_receivable',
        name: 'add_accounts_receivable',
        report: 'add_accounts_receivable_report',
        component: () => import('@/views/accounts-receivable/add'),
        meta: {title: '收款单', icon: 'add_account_nav' },
      },
      {
        name: 'add_accounts_receivable_report',
        path: 'add_accounts_receivable_report',
        meta: {
          title: '收款单报表',
          activeMenu: '/financial_statements/add_accounts_receivable'
        },
        component: () => import('@/views/accounts-payable/list'),
        hidden: true,
      },
      {
        path: 'accounts_payable',
        name: 'accounts_payable',
        component: () => import('@/views/accounts-payable/index'),
        meta: {title: '应付欠款', icon: 'accounts-payable-nav'}
      },
      {
        path: 'add_accounts_payable',
        name: 'add_accounts_payable',
        report: 'add_accounts_payable_report',
        component: () => import('@/views/accounts-payable/add'),
        meta: {title: '付款单', icon: 'add_account_nav' },
      },
      {
        name: 'add_accounts_payable_report',
        path: 'add_accounts_payable_report',
        meta: {
          title: '付款单报表',
          activeMenu: '/financial_statements/add_accounts_payable'
        },
        component: () => import('@/views/accounts-payable/list'),
        hidden: true,
      },
      {
        name: 'add_accounts_payable_detail',
        path: 'add_accounts_payable_detail/:_pid',
        meta: {
          title: '付款单详情',
          activeMenu: '/financial_statements/add_accounts_payable',
        },
        component: () => import('@/views/accounts-payable/add'),
        hidden: true,
      },
    ]
  },
  {
    path: '/system_settings',
    component: Layout,
    name: 'system_settings',
    meta: {title: '系统设置', icon: 'basic-setting-nav'},
    children: [
      {
        path: 'print_template',
        name: 'print_template',
        component: () => import('@/views/print-template/index'),
        meta: { title: '打印模板',  icon: 'print-template-nav' }
      },
      {
        path: 'employee_settings',
        name: 'employee_settings',
        component: () => import('@/views/employee-settings/index'),
        meta: { title: '职员',  icon: 'employee-settings-nav' }
      },
      //   path: 'account_set_management',
      //   name: 'account_set_management',
      //   component: () => import('@/views/account-set-management/index'),
      //   meta: { title: '账套管理',  }
      // },
      // {
      //   path: 'operator_settings',
      //   name: 'operator_settings',
      //   component: () => import('@/views/operator-settings/index'),
      //   meta: { title: '操作员设置',  }
      // },
      // {
      //   path: 'role_management',
      //   name: 'role_management',
      //   component: () => import('@/views/role-management/index'),
      //   meta: { title: '角色管理',  }
      // },
      // {
      //   path: 'system_settings',
      //   name: 'system_settings',
      //   component: () => import('@/views/system-settings/index'),
      //   meta: { title: '系统设置',  }
      // },
      // {
      //   path: 'department_management',
      //   name: 'department_management',
      //   component: () => import('@/views/department-management/index'),
      //   meta: { title: '部门管理',  }
      // },
      // {
      // {
      //   path: 'data_backup',
      //   name: 'data_backup',
      //   component: () => import('@/views/data-backup/index'),
      //   meta: { title: '数据备份',  }
      // },
      // {
      //   path: 'system_upkeep',
      //   name: 'system_upkeep',
      //   component: () => import('@/views/system-upkeep/index'),
      //   meta: { title: '系统维护',  }
      // },
    ]
  },
  { path: '*', redirect: '/404', hidden: true }

];

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: [...constantRoutes, ...myrouter]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
